package logic

import (
	"community/communityrpc/communityrpc"
	"context"

	"community/api/internal/svc"
	"community/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type RetrieveLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRetrieveLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RetrieveLogic {
	return &RetrieveLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RetrieveLogic) Retrieve(req *types.RetrieveRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	retrieve, err := l.svcCtx.CommunityRpc.Retrieve(l.ctx, &communityrpc.RetrieveRequest{
		Account:         req.Account,
		NewPassword:     req.NewPassword,
		ConfirmPassword: req.ConfirmPassword,
		Password:        req.Password,
		SendSms:         req.SendSms,
		SendPassword:    req.SendPassword,
	})

	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "密码找回成功",
		Code:    200,
		Data:    retrieve,
	}, nil
}
